package org.example.login;

import org.example.util.FrameUtil;

import javax.swing.*;
import java.awt.*;

/**
 * @author :Mr.zhou
 * @description: 用户登录窗口
 * @create date: 2025/2/21 16:37
 */
public class LoginMain {
    public static void main(String[] args) {

        System.setProperty("sun.java2d.opengl", "true");
        System.setProperty("sun.java2d.d3d", "true");

        JFrame frame = new JFrame("Frame");
        frame.setSize(320, 448);
        // 初始化窗口图标数据
        FrameUtil.initFrame(frame, "系统登录", "/00.png");

        LoginPenal loginPenal = new LoginPenal("/bg001.jpg");
        frame.add(loginPenal);

        loginPenal.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();

        JPanel jPanel=new JPanel();
        jPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
        // 关键设置：禁用不透明属性
        jPanel.setOpaque(false);
        JLabel title = new JLabel("开 心 周(*￣︶￣)");
        title.setForeground(Color.WHITE);
        Font customFont = new Font("微软雅黑", Font.BOLD, 16);
        title.setFont(customFont);
        jPanel.add(title);
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 3;
        gbc.insets = new Insets(0, 0, 30, 0);
        loginPenal.add(jPanel, gbc);

        // 第1行第1列（占1行2列）
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.gridwidth = 1;
        JLabel userLable = new JLabel("用户名：", SwingConstants.LEFT);
        userLable.setForeground(Color.white);
        loginPenal.add(userLable, gbc);
        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.gridwidth = 2;
        JTextField uertxt = new JTextField(16);
        loginPenal.add(uertxt, gbc);

        // 一个中文相当于4个空格
        JLabel pwdLable = new JLabel("密    码：", SwingConstants.LEFT);
        pwdLable.setForeground(Color.white);
        JPasswordField jPasswordField = new JPasswordField(16);

        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.gridwidth = 1;
        gbc.insets = new Insets(20, 0, 0, 0);
        loginPenal.add(pwdLable, gbc);
        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.gridwidth = 2;
        loginPenal.add(jPasswordField, gbc);

        JButton loginBut = new JButton("登录");
        JButton registerBut = new JButton("注册");

        JPanel jPanel2=new JPanel();
        jPanel2.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 10));
        // 关键设置：禁用不透明属性
        jPanel2.setOpaque(false);
        jPanel2.add(loginBut, gbc);
        jPanel2.add(registerBut, gbc);
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.gridwidth = 3;
        gbc.insets = new Insets(20, 10, 0, 0);
        loginPenal.add(jPanel2, gbc);
        //设置窗口是否可见
        frame.setVisible(true);
    }

}
